package com.choudou5.spider.config;

import cn.hutool.core.collection.CollUtil;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @name 任务对象
 * @author choudou5
 * @date 2018-08-21
 */
public class TaskBean implements Serializable {

    private String id;
    private String type;    //类型：list=列表，detail=详情
    private String title;
    private Integer version;    //任务版本号
    private Integer pageSize;
    private Boolean useProxy = false;

    //定时
    private Boolean startup = false;    //是否开机启动
    private Integer minIntervalTime = 3000; //最小间隔
    private Integer delay = 3000;   //延迟执行

    //请求参数
    private String method;  //方式：GET/POST
    private String parseType;   //解析类型：json/html
    private String encoding = "utf-8";
    private String detailEncoding = "utf-8";
    private String api;     //api地址
    private String headers;
    private String cookies;
    private String contentLocationRule;     //内容定位规则（定位列表或详情主体的规则）

    private TableBean table;   //表

    private List<FormParam> formParams;     //表单参数

    private List<RespNextReqParam> respNextReqParams;

    public boolean isNewVersion(Integer version) {
        if(version != null)
            return getVersion() < version;
        return false;
    }

    public String getId() {
        return id;
    }


    public void setId(String id) {
        this.id = id;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Boolean getUseProxy() {
        return useProxy;
    }

    public void setUseProxy(Boolean useProxy) {
        this.useProxy = useProxy;
    }

    public Boolean isStartup() {
        return startup;
    }

    public void setStartup(Boolean startup) {
        this.startup = startup;
    }

    public Integer getMinIntervalTime() {
        return minIntervalTime;
    }

    public void setMinIntervalTime(Integer minIntervalTime) {
        this.minIntervalTime = minIntervalTime;
    }

    public Integer getDelay() {
        return delay;
    }

    public void setDelay(Integer delay) {
        this.delay = delay;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getParseType() {
        return parseType;
    }

    public void setParseType(String parseType) {
        this.parseType = parseType;
    }

    public String getEncoding() {
        return encoding;
    }

    public void setEncoding(String encoding) {
        this.encoding = encoding;
    }

    public String getDetailEncoding() {
        return detailEncoding;
    }

    public void setDetailEncoding(String detailEncoding) {
        this.detailEncoding = detailEncoding;
    }

    public String getApi() {
        return api;
    }

    public void setApi(String api) {
        this.api = api;
    }

    public String getHeaders() {
        return headers;
    }

    public void setHeaders(String headers) {
        this.headers = headers;
    }

    public String getCookies() {
        return cookies;
    }

    public void setCookies(String cookies) {
        this.cookies = cookies;
    }

    public String getContentLocationRule() {
        return contentLocationRule;
    }

    public void setContentLocationRule(String contentLocationRule) {
        this.contentLocationRule = contentLocationRule;
    }

    public TableBean getTable() {
        return table;
    }

    public void setTable(TableBean table) {
        this.table = table;
    }

    public List<String> getFieldList() {
        List<FieldBean> fieldList = table.getFields();
        if(CollUtil.isNotEmpty(fieldList)){
            List<String> fields = new ArrayList<>();
            for (FieldBean field : fieldList) {
                fields.add(field.getName());
            }
            return fields;
        }
        return null;
    }

    public List<FormParam> getFormParams() {
        return formParams;
    }

    public void setFormParams(List<FormParam> formParams) {
        this.formParams = formParams;
    }

    public List<RespNextReqParam> getRespNextReqParams() {
        return respNextReqParams;
    }

    public void setRespNextReqParams(List<RespNextReqParam> respNextReqParams) {
        this.respNextReqParams = respNextReqParams;
    }
}
